package com.hxm.appGenealogy.controller;

import com.hxm.appGenealogy.config.Constant;
import com.hxm.appGenealogy.entity.*;
import com.hxm.appGenealogy.service.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * 家族树;
 */
@CrossOrigin
@RestController
@RequestMapping("app/tree")
public class TreeController {


    @Autowired
    private TreeService treeService;

    //添加人的信息;
    @PostMapping("addpeople")
    public ResponDataVo addPeople(@RequestBody People people){
        ResponDataVo responDataVo = treeService.addPeople(people);
        return responDataVo;
    }
    /**
     * 添加父亲;
     * @param peopleVo
     * @return
     */
    @PostMapping("addfather")
    public ResponDataVo addFather(@RequestBody PeopleVo peopleVo){
        peopleVo.setIsHavePit(1);
        if(peopleVo.getAvater()==null){
            peopleVo.setAvater("http://liuguangtec.com/static/nanT.png");
        }
        return treeService.addFather2(peopleVo);
    }


    /**
     * 添加母亲;
     * @param peopleVo
     * @return
     */
    @PostMapping("addmother")
    public ResponDataVo addMonther(@RequestBody PeopleVo peopleVo){
        peopleVo.setIsHavePit(1);
        if(peopleVo.getAvater()==null){
            peopleVo.setAvater("http://liuguangtec.com/static/nvT.png");
        }
        return treeService.addMonther2(peopleVo);
    }

    /**
     * 添加兄弟;
     *添加兄弟姐妹的信息,将兄弟姐妹添加到我的兄弟姐妹里面,在将他和我的兄弟姐妹之间做一个相互的绑定,
     * 将我新添加的兄弟姐妹添加到我父母的下面
     * 应为添加父母的时候会将下面的我的兄弟姐妹进行添加,所以会造成冲突,
     * 兄弟姐妹所以会判断父母有没有添加过这个兄弟姐妹,如果没有添加过在进行添加;
     * @param peopleVo
     * @return
     */
    @PostMapping("addbrother")
    public ResponDataVo addBrother(@RequestBody PeopleVo peopleVo){
        peopleVo.setIsHavePit(1);
        if(peopleVo.getAvater()==null){
            if(peopleVo.getGender().equals(Constant.genderboy)){
                peopleVo.setAvater("http://liuguangtec.com/static/nanT.png");
            }else {
                peopleVo.setAvater("http://liuguangtec.com/static/nvT.png");
            }
        }
        return treeService.addBrother(peopleVo);
    }


    /**
     * 添加妻子,
     * 添加妻子的时候要注意,判断我是否有儿子,将儿子的数据添加到我妻妻子的下面去;
     * 如果儿子存在就进行添加如果不存在就不进行添加;
     * @return
     */
    @PostMapping("addwifePeopleId")
    public ResponDataVo addWifePeopleId(@RequestBody PeopleVo peopleVo){
        peopleVo.setIsHavePit(1);
        if(peopleVo.getAvater()==null){
            peopleVo.setAvater("http://liuguangtec.com/static/nvT.png");
        }
        return treeService.addWifePeopleId(peopleVo);
    }


    /**
     * 添加丈夫;
     */
    @PostMapping("addHusPeopleId")
    public ResponDataVo addHusPeopleId(@RequestBody PeopleVo peopleVo){
        peopleVo.setIsHavePit(1);
        if(peopleVo.getAvater()==null){
            peopleVo.setAvater("http://liuguangtec.com/static/nanT.png");
        }
        return treeService.addHusPeopleId(peopleVo);
    }

    /**
     * 添加儿子/女儿;
     */
    @PostMapping("addSon")
    public ResponDataVo addSon(@RequestBody PeopleVo peopleVo){
        peopleVo.setIsHavePit(1);
        if(peopleVo.getAvater()==null){
            if(peopleVo.getGender().equals(Constant.genderboy)){
                peopleVo.setAvater("http://liuguangtec.com/static/nanT.png");
            }else {
                peopleVo.setAvater("http://liuguangtec.com/static/nvT.png");
            }
        }
        return treeService.addSon(peopleVo);
    }
    /**'
     * 查询家族;
     * @param family
     * @return
     */
    @PostMapping("selectFamily")
    public ResponDataVo selectFamily(@RequestBody Family family){
        return treeService.selectFamily(family);
    }

    /**
     * 查询是否有数据;
     * @param people
     * @return
     */
    @PostMapping("selectrelation")
    public ResponDataVo selectRelation(@RequestBody PeopleVo people){
        return treeService.selectRelation(people);
    }

    /**
     *删除数的节点;
     */
    @PostMapping("delTreeNode")
    public ResponDataVo delTreeNode(@RequestBody PeopleVo people){
        return treeService.delTreeNode(people);
    }
}











